#include <iostream>

class ScopeGuard {
public:
    ~ScopeGuard() {
        std::cout << "Clean up resources here" << std::endl;
        // 执行必要的清理工作，例如关闭文件、释放锁等
    }
};

void processFile() {
    ScopeGuard guard; // 无论如何离开，都会调用析构函数

    // 正常的处理逻辑
    std::cout << "Processing file" << std::endl;

    // 假设在此抛出异常
    throw std::runtime_error("Failed to process file");

    std::cout << "File processed successfully" << std::endl;
}

int main() {
    try {
        processFile();
    } catch (const std::exception& e) {
        std::cout << "Exception caught: " << e.what() << std::endl;
    }
}